<?php namespace Admin\Controller; 

use Hdphp\Controller\Controller;

//测试控制器
class BrandController extends CommonController{
	private $brandModel;
	//构造函数
	public function __init()
	{
		parent::__init();
		$this->brandModel = new \Common\Model\Brand;
	}
	
//	首页显示
	public function index(){
//		调取数据库数据
		$total = $this->brandModel->count();
		$page = Page::row(10)->desc(array('pre'=>'<<上一页', 'next'=>'下一页>>'))->make($total);
		$brandData = $this->brandModel->limit(Page::limit())->get();
		View::with('page',$page);
		View::with('brandData',$brandData);
		View::make();
	}
	
//	添加品牌
	public function add(){
//		获得要添加
		if(IS_POST){
			if(!$this->brandModel->stroe()) View::error($this->brandModel->getError());
			View::success('添加成功！','index');
		}
		View::make();
	}
	
//	编辑品牌
	public function edit(){
		$bid = Q('get.bid',0,'intval');
		$oldData = $this->brandModel->where("bid = {$bid}")->find();
		if(IS_POST){
			if(!$this->brandModel->edit()) View::error($this->brandModel->getError());
			View::success('修改成功！','index');
		}
		View::with('oldData',$oldData);
		View::make();
	}
	
//	删除品牌
	public function del(){
		$bid = Q('get.bid',0,'intval');
//		小图地址
		$path = $this->brandModel->where("bid = {$bid}")->pluck('logo');
		unlink($path);
		$this->brandModel->where("bid = {$bid}")->delete();
		View::success('删除成功！','index');
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
}
